//    Copyright (C) Kherty.  All rights reserved.

using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;

namespace OpenLS.Chart.UI
{
    partial class MarkerPropertiesResources
    {
        public MarkerPropertiesResources()
        {
            InitializeComponent();
        }

        private void OnNoneClick(object sender, RoutedEventArgs e)
        {
            GetMarker(sender).Symbol = MarkerStyle.None;

        }

        private void OnBuiltInClick(object sender, RoutedEventArgs e)
        {
            var b = (RadioButton) sender;
            var cb = (ComboBox) b.Tag;
            var m = SeriesElement.GetMarker(b);
            if (cb.SelectedIndex == -1)
                cb.SelectedIndex = 0;
            m.Symbol = (MarkerStyle?) cb.SelectedItem;

        }

        private static Marker GetMarker(object sender)
        {
            return SeriesElement.GetMarker((DependencyObject) sender);
        }

        private void OnAutomaticClick(object sender, RoutedEventArgs e)
        {
            GetMarker(sender).Symbol = null;

        }

        private void ComboBox_Loaded(object sender, RoutedEventArgs e)
        {
            var cb = (ComboBox) sender;
            var styles = new List<MarkerStyle>();
            for (int i = 0; i < 9; i++)
                styles.Add(MarkerStyleSizeToPathDataConverter.GetMarkerStyleFromIndex(i));
            cb.DataContext = styles;
        }


        private void AutomaticLoaded(object sender, RoutedEventArgs e)
        {
            Marker m = GetMarker(sender);
            if (m.Symbol == null)
                ((RadioButton) sender).IsChecked = true;
        }

        private void NoneLoaded(object sender, RoutedEventArgs e)
        {
            Marker m = GetMarker(sender);
            if (m.Symbol != null && m.Symbol.Value == MarkerStyle.None)
                ((RadioButton)sender).IsChecked = true;

        }

        private void BuiltInLoaded(object sender, RoutedEventArgs e)
        {
            Marker m = GetMarker(sender);
            if (m.Symbol != null && m.Symbol.Value != MarkerStyle.None)
                ((RadioButton)sender).IsChecked = true;

        }


        private void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;
            Marker m = GetMarker(sender);
            m.Symbol = (MarkerStyle) e.AddedItems[0];
        }
    }
}
